<div class="block">
<?php
class apartment_property
{
	protected	$_group = 1;
	protected	$_limit = 5;
	protected	$_category_id = 1;
	protected	$_DBconn;
	protected	$_front_template;
	protected	$_view;
	protected	$_currency;	
	protected	$_group_db;
	protected	$translator;
	
	public function __construct($view) 
	{
		$this->_front_template = Zend_Registry::get('front_template'); 
		$this->_view =	$view;
		
		//DB Connection
		$this->_DBconn = Zend_Registry::get('msqli_connection');
		$this->_DBconn->getConnection();
		
		$this->translator = Zend_Registry::get('translator');	
		
		//DD Class
		$global_conf 				= Zend_Registry::get('global_conf');
		$this->_currency 			= new Zend_Currency($global_conf['default_locale']);
		$this->_group_db 			= new Property_Model_DbTable_PropertyGroup();
	}
	
	public function truncate($phrase,$start_words, $max_words)
	{
	   $phrase_array = explode(' ',$phrase);
	   if(count($phrase_array) > $max_words && $max_words > 0)
		  $phrase = implode(' ',array_slice($phrase_array, $start_words, $max_words)).'...';  
	   return $phrase;
	}
	
	public function class_body()
	{		
		$groupInfo	=	$this->_group_db->getGroupName($this->_group);
		
		$select = $this->_DBconn->select()
						->from(array('pp' => Zend_Registry::get('dbPrefix').'property_page'), array('*'))
						->where('pp.active = ?', '1')
						//->where('pp.featured = ?', '1')
						->where('pp.group_id = ?', $this->_group)
						->where('pp.category_id = ?', $this->_category_id)
						->order("pp.".$groupInfo['latest_file_sort']." ".$groupInfo['latest_file_order'])
						->joinLeft(array('pc' => Zend_Registry::get('dbPrefix').'property_category'), 'pp.category_id = pc.id', array('category_name' => 'pc.category_name', 'category_title' => 'pc.category_title'))
						->joinLeft(array('ct' => Zend_Registry::get('dbPrefix').'cities'), 'pp.area_id = ct.city_id', array('city' => 'ct.city'))
						->joinLeft(array('st' => Zend_Registry::get('dbPrefix').'states'), 'pp.state_id = st.state_id', array('state_name' => 'st.state_name'))
						->limit($this->_limit);
		$property_info =  $select->query()->fetchAll();	
		$maximum_stars_digit = $this->translator->translator('maximum_stars_digit', '', 'Property');
	
		if($property_info)
		{
			foreach($property_info as $entry)
			{
				$property_image_val_arr = explode(',',$entry['property_image']);
				$property_image_no = (!empty($property_image_val_arr[0])) ? count($property_image_val_arr) : '0';
				if($this->_view->escape($entry['property_primary_image']))
				{ 
					$thumb_image = 'data/frontImages/property/property_image/'.$this->_view->escape($entry['property_primary_image']); 
				}
				else
				{ 
					if($this->_view->escape($entry['property_image']))
					{					
						$thumb_image = 'data/frontImages/property/property_image/'.$this->_view->escape($property_image_val_arr[0]); 
					}
					else
					{
						$thumb_image = 'application/layouts/scripts/'.$this->_front_template['theme_folder'].'/images/mod_property_img/no_image.png'; 
					}		
				}			
		?>          
			<div class="img-wrapper">
				<a href="<?php echo $this->_view->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->_view->escape($entry['property_title']) ),'Property-details/:property_title',true); ?>" link="<?php echo $thumb_image; ?>"  title="<?php echo $this->_view->escape($entry['property_name']); ?>" width="100" height="110" class="preview"><div class="lazy" width="80" height="90" border="0" data-original="<?php echo $thumb_image; ?>" style=""></div></a>
                <div class="photo-count-container">
                	<div class="photo-count"><a href="<?php echo $this->_view->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->_view->escape($entry['property_title']), 'tab' => '1' ),'Property-details/:property_title/:tab',true); ?>"><?php echo $this->translator->translator('property_front_page_property_photo_no', $property_image_no, 'Property'); ?></a></div>
                </div>
			</div>
					
            <div class="details">
            	<h2><a href="<?php echo $this->_view->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->_view->escape($entry['property_title']) ),'Property-details/:property_title',true); ?>" title="<?php echo $this->_view->escape($entry['property_name']); ?>" link="" class="preview"><?php echo $this->truncate($this->_view->escape($entry['property_name']), 0, 6); ?></a></h2>
                <?php
					for($i = 1; $i < $maximum_stars_digit; $i++)
					{
						$property_stars = ($i <= $this->_view->escape($entry['stars'])) ? "<img class='lazyLoad' data-original='application/layouts/scripts/".$this->_front_template['theme_folder']."/images/mod_property_img/star-small-active.png' border='0' />" : "<img class='lazyLoad' data-original='application/layouts/scripts/".$this->_front_template['theme_folder']."/images/mod_property_img/star-small-inactive.png' border='0' />";
						echo $property_stars.'&nbsp;';
					}
				?>
             	<span class="info">&nbsp; | <?php echo $this->translator->translator('property_front_page_property_location', '', 'Property'); ?> <a href="<?php echo $this->_view->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->_view->escape($entry['property_title']) ),'Property-details/:property_title',true); ?>"><?php echo $this->_view->escape($entry['city'].' / '.$entry['state_name']); ?></a> &nbsp;|&nbsp; <?php echo (int)$this->_view->escape($entry['feature_room_no']).' '.$this->translator->translator('partial_featured_property_room').','; ?> <?php echo (int)$this->_view->escape($entry['feature_bathroom']).' '.$this->translator->translator('partial_featured_property_bathroom'); ?></span><br />
                <div class="price price-big"><?php echo $this->_currency->getSymbol().$this->_view->escape($entry['property_price']); ?></div>
                <?php echo $this->truncate($this->_view->escape(strip_tags($entry['property_desc'])), 0, 20); ?>
                <div class="link-btn"><a href="<?php echo $this->_view->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'details','property_title' => $this->_view->escape($entry['property_title']) ),'Property-details/:property_title',true); ?>" ><?php echo $this->translator->translator('block_details_link','','', $this->_front_template['theme_folder']); ?></a></div>
           	</div>
           	<div class="seperator"></div>
		<?php
			}
		?>
			<div class="more"><a href="<?php echo $this->_view->url(array('module' => 'Property','controller' =>'frontend', 'action' => 'category','category_id' => $this->_view->escape($entry['category_id']) ),'Category-List/:category_id',true); ?>"><?php echo $this->translator->translator('block_tab_more',$this->_view->escape($entry['category_name']),'', $this->_front_template['theme_folder']); ?></a></div>
	<?php
		}
	}
}
try
{
	$apartment_property_class = new apartment_property($this);
	$apartment_property_class->class_body();
}
catch(Exception $e)
{
	echo $e->getMessage();
}
?>
</div>